#ifndef LOADER_H
#define LOADER_H

#include <string>
#include <unordered_map>

#include "assimp/scene.h"
#include "assimp/mesh.h"
#include "assimp/material.h"

#include "util.h"
#include "Material.h"
#include "Geometry.h"
namespace renderengine
{
    class Node;
    class Loader {
    public:
        Loader();
        ~Loader();

        std::shared_ptr<Node> load(std::string filename);
    private:
        void loadScene(const aiScene* rawScene, std::shared_ptr<Node> node);
        void loadNode(const aiScene* rawScene, const aiNode* rawNode, std::shared_ptr<Node> node);
        void loadMesh(const aiScene* rawScene, const aiNode* rawNode, std::shared_ptr<Node> node);
        void loadMesh(const aiScene* rawScene, unsigned int meshIndex, std::shared_ptr<Node> node);
        void loadGeometry(const aiScene* rawScene, unsigned int meshIndex, std::shared_ptr<Node> node);
        void loadMaterial(const aiScene* rawScene, unsigned int materialIndex, std::shared_ptr<Node> node);
        void loadTextures(const aiMaterial* rawMaterial, std::shared_ptr<Node> node, std::shared_ptr<Material> material);
        void loadNodeChildren(const aiScene* rawScene, const aiNode* rawNode, std::shared_ptr<Node> node);
        void setTransformation(const aiNode* rawNode, std::shared_ptr<Node> node);

        std::shared_ptr<Geometry> createGeometry(const aiMesh* rawMesh);
        std::shared_ptr<Geometry> createMesh(const aiMesh* rawMesh);
        std::shared_ptr<Geometry> createMultiPoint(const aiMesh* rawMesh);
        std::shared_ptr<Geometry> createMultiLine(const aiMesh* rawMesh);
        std::shared_ptr<Material> createMaterial(const aiMaterial* rawMaterial);

        std::unordered_map<unsigned int, std::shared_ptr<Geometry>> mGeometries;
        std::unordered_map<unsigned int, std::shared_ptr<Material>> mMaterials;

    };
}
#endif // !LOADER_H
